<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 							
		<%@ include file="../jslib/jquerylib.jsp" %>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
	 <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
	
    <script type="text/javascript">
     var api = frameElement.api, W = api.opener;
    $().ready(function() {
			
    	// 准备好Options对象
    	var options = {
    	    url:'<%=request.getContextPath()%>/auto!saveGwmItem.action',
    	    dataType:'json',
    	    success: function(data) {
    	      if(data.result=='success'){
				alert("添加成功");
				$("#T_JIACEBIAOZHUN").val('');
				$("#T_JIANCECANSHU").val('');
    	      }else{
    	      	alert("系统繁忙，请您稍后再试！");
    	      }
    	    }
    	  };
		$('#saveBtn').click(function(){
		    var msg = "检测项目、检测单位";
		    if($.trim($("#T_ITEMNAME").val())==''){
		      alert("请填写检测项目");
		      return false;
		    }
		    if($.trim($("#T_JIANCEDANWEI").val())==''){
		      alert("请填写检测单位");
		      return false;
		    }
		    var valueMsg1 = "T_ITEMNAME='"+$.trim($("#T_ITEMNAME").val())+"' and T.T_JIANCEDANWEI="+$.trim($("#T_JIANCEDANWEI").val());
    	   
    	   //首先判断检测项目和检测单位是否存在 
    	    var flag = checkMessageWeiyi('GWM_ITEM T  ','',valueMsg1);
    	    if(flag=='true'){
    	    
    	        var biaozhun = '';
    	        //判断该检测项目、检测单位、检测标准是否存在
    	        if($.trim($("#T_JIACEBIAOZHUN").val())!=''){
    	          var  valueMsg2  = valueMsg1+" AND T.T_JIANCEBIAOZHUN='"+$.trim($("#T_JIACEBIAOZHUN").val())+"'";
    	           var flag1 = checkMessageWeiyi('GWM_ITEM T  ','',valueMsg2);
    	       
	    	       if(flag1=='true'){
	    	              msg = msg+"、检测标准";
	    	              alert(msg+"已存在,请重新输入!");
		    	          return false;
		    	   }else{
		    	          valueMsg1  = valueMsg1+" AND T.T_JIANCECANSHU='"+$.trim($("#T_JIANCECANSHU").val())+"'";
    	                  msg = msg+"、检测参数";
		    	          var flag2 = checkMessageWeiyi('GWM_ITEM T  ','',valueMsg1);
		    	          if(flag2=='true'){
		    	            alert(msg+"已存在,请重新输入!");
		    	            return false;
		    	          }
		    	   }
    	        }
	    	   //判断检测参数是否存在
	    	   else if($.trim($("#T_JIANCECANSHU").val())!=''){
    	            valueMsg1  = valueMsg1+" AND T.T_JIANCECANSHU='"+$.trim($("#T_JIANCECANSHU").val())+"'";
    	            msg = msg+"、检测参数";
	    	        var flag2 = checkMessageWeiyi('GWM_ITEM T  ','',valueMsg1);
	    	        if(flag2=='true'){
	    	            alert(msg+"已存在,请重新输入!");
	    	            return false;
	    	        }
    	       }
    	       else {
    	              alert(msg+"已存在,请重新输入!");
	    	          return false;
    	       }
	    	   
    	    }
    	    else if(flag=='error'){
    	       return false;
    	    }
			$('#pageFrom').ajaxSubmit(options);
			return false;
		});
		
		$('#closeBtn').click(function(){
			api.close();
			W.gridSearchItemGrid();
		});
	});
	
	//选择部门
	function selectdept(id)
	{
		var datas = window.showModalDialog("<%=request.getContextPath()%>/resource/choose/choose_organizationIndex.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("dept_"+id).value = json1.ORG_NAME;
			 document.getElementById(id).value = json1.ORG_ID;
		}
	}
	//选择外键数据信息
	//参数信息：表明，关联列，显示列
	function selectData(id,tablename,colname,disname,cnname,fieldslist,formid){
	    var fileColname ='hideFileName';
	    if(tablename=='DIC_STANDARD'){
	      fileColname = "YCLJS_GYYW";
	    }
	    var   datas = window.showModalDialog("<%=request.getContextPath()%>/auto!chooseDatalist.action?byTableValueId=null&tablename="+tablename+"&colname="+colname+"&disname="+disname+"&cnname="+escape(encodeURIComponent(cnname))+"&fileColname="+fileColname+"&formid="+formid+"&fileName="+id+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=800px;dialogHeight=500px");
	       if(typeof(datas) == 'undefined'){
		   }else{
			 var json1 = eval('(' + datas + ')');
			 document.getElementById(id).value = json1.ID;
			
			 var disnamearray = disname.split(',');
			 //检测项目管理  添加页面选择检测单位
			     $("#T_JIANCEDANWEI_NAME").val(json1.T_JIANCEDANWEI);  
			     $("#T_GONGSIDAIMA").val(json1.T_GONGSIDAIMA);
			     $("#T_JIANCEDIDIAN").val(json1.T_JIANCEDIDIAN);
			}
			 
			 
	}
	//判断是否唯一
	function checkMessageWeiyi(tableName,columName,valueMsg){
	  var flag = 'error';
	  var  params = {
	               "tableName":tableName,
	               "flowtaskid":'',
	               "columName":columName,
	               "valueMsg":encodeURIComponent(valueMsg)
	              };
	  $.ajax({
			type: "POST",
			url :'<%=request.getContextPath()%>/auto!checkMessageWeiyi.action',  
			dataType: "json",
			data:params,
			async: false,//取消异步提交
			success : function(data, textStatus) {  
				if(data.result=='error'){
				   alert("校验唯一性失败!");
				   flag = 'error';
				}
				flag = data.result;
			},
			error:function(){}
		});
		return flag;
	}
</script>
<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
</head>
<body >
  	<form  id="pageFrom" name="pageFrom" class="easyui-form" data-options="novalidate:true" method="post">
  		<input type="hidden" id="formid" name="formid" value="3942"/>
  		<input type="hidden" id="columns" name="columns" value="T_ITEMNAME,T_JIANCEDANWEI,T_GONGSIDAIMA,T_JIANCEDIDIAN,T_JIANCEBUMEN,T_JIACELEIBIE,T_JIANCEMONEY,"/>
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  			<tr>
	  			<td align="right">检测项目：</td>
	  			<td align="left">
	  			   <input  type="text"  id="T_ITEMNAME"   name="T_ITEMNAME" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
	  			   <img src="<%=request.getContextPath()%>/images/xh.png" align="absmiddle"></img>
	  			</td>
	  			<td align="right">检测单位：</td>
	  			<td align="left">
	  			   <input type="hidden" id="T_JIANCEDANWEI"  name="T_JIANCEDANWEI">
	  			   <input type="text" readonly=readonly id="T_JIANCEDANWEI_NAME"    name="T_JIANCEDANWEI_NAME" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
	  			   <img src="<%=request.getContextPath()%>/images/xh.png" align="absmiddle"></img>
	  			   <img src="<%=request.getContextPath()%>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectData('T_JIANCEDANWEI','GWM_JIANCEDANWEI','ID','T_JIANCEDANWEI,T_GONGSIDAIMA,T_JIANCEDIDIAN','检测单位','null','3942')" />
	  			</td>
  		    </tr>
  		    <tr>
  		        <td align="right">检测单位代码：</td>
  		        <td align="left">
  		          <input readonly=readonly type="text"  id="T_GONGSIDAIMA"   name="T_GONGSIDAIMA" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		        </td>
  		        <td align="right">检测地点：</td>
  		        <td align="left">
  		           <input  type="text"  id="T_JIANCEDIDIAN"   name="T_JIANCEDIDIAN" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		        </td>
  		    </tr>
  		    <tr>
  		       <td align="right">检测部门：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIANCEBUMEN"   name="T_JIANCEBUMEN" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		       </td>
  		       <td align="right">检测类别：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIACELEIBIE"   name="T_JIACELEIBIE" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		       </td>
  		   </tr>
  		   <tr>
  		       <td align="right">检测费用：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIANCEMONEY"   name="T_JIANCEMONEY" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		       </td>
  		       <td align="right">检测标准：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIACEBIAOZHUN"   name="T_JIACEBIAOZHUN" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		       </td>
  		       <input type='hidden' id="ID" name="ID"/>
  		   </tr>
  		     <tr>
  		       <td align="right">检测参数：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIANCECANSHU"   name="T_JIANCECANSHU" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  		       </td>
  		       <td align="right"></td>
  		       <td align="left">
  		       </td>
  		       <input type='hidden' id="ID" name="ID"/>
  		   </tr>
		</table>
		<table width="100%" border="0" align="center" class="formTableNew">
			<td align="center">
		    	
		    	<input id="saveBtn" type="button" value="保 存" class="form_bt_orange" />
		        
		      	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		</table>
	</form>
  </body>
</html>

